'use strict';

import * as actions from '../../actions/mjs1_list';

// 对页面prop 数据进行管理
const initialState = {
  data: [],
  total:0,
  counter: 0,
  loginError:false,
  creating:false,
  message:"",
  error:false,
};
const defaultAction = {
  type: 'doNothing'
};

export default function index(state = initialState, action = defaultAction) {
  switch (action.type) {

    case actions.GET_LIST_START:

      return Object.assign({}, state, {
    	  creating: true,
        counter: action.data,
        mjs_data:false
      });

    case actions.GET_LIST_SUCCESS:
      return Object.assign({}, state, {
    	  creating: false,
        data: action.data,
        total:action.total
      });
    case actions.REMOVE_MJS :
    	state.data.map((mjs,key)=>{
    		if(mjs.id==action.id){
    			state.data.splice(key,1)
    		}
    	})
    	return Object.assign({}, state, {
    		creating: false,
        });
    case actions.GET_MJS_SUCCESS:
      return Object.assign({}, state, {
    	  creating: false,
        mjs_data: action.data,
        mjsDialog:true
      });

    case actions.CLOSE_MJS_DIALOG:
      return Object.assign({}, state, {
    	  creating: false,
        mjs_data: false,
        mjsDialog:false
      });

    case actions.LOAD_ERR:

      return Object.assign({}, state, {
    	  creating:false,
	  		error:true,
	  		loginError:action.loginFalse,
	  		message:action.message
      });
    case actions.CLOSE_DIALOG:
        return Object.assign({}, state, {
        	 error:action.visible,
          loginError:false
        });
  	  break;
    default:
      return state;
  }
}



